package com.geoboard.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.geoboard.ActivityInterface;
import com.geoboard.R;

public class BoardMapFrag extends Fragment{

	/**** Members **************************************************/
	private String TAG = this.getClass().getSimpleName();
	private MapFrag mMap;

	/**** Android Callback Methods *********************************/
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);	
		mMap = ((ActivityInterface)getActivity()).getMapFrag();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		Log.d(TAG, "onCreateView");
		ViewGroup root = (ViewGroup) inflater.inflate(R.layout.frag_board_map, container, false);		
		
		ImageView createBut = (ImageView)root.findViewById(R.id.create_button);
		
		createBut.setOnClickListener(new OnClickListener() {
		    public void onClick(final View createBut) {
		    	createBoard();
		     }
		 });
		
		return root;
	}
	
	@Override
	public void onAttach(Activity activity){
		super.onAttach(activity);		
	}
	
	@Override
	public void onActivityCreated (Bundle savedInstanceState){
		super.onActivityCreated(savedInstanceState);
	}
	
	@Override
	public void onViewStateRestored (Bundle savedInstanceState){
		super.onViewStateRestored(savedInstanceState);
	}
	
	@Override
	public void onStart(){
		Log.d(TAG, "onStart");
		super.onStart();
		mMap.getBoards();
	}
	
	@Override
	public void onResume(){
		Log.d(TAG, "onResume");
		super.onResume();		
	}
		
		
	
	@Override
	public void onPause(){
		super.onPause();	
	}
	
	@Override
	public void onStop(){
		super.onStop();
	}
	
	
	@Override
	public void onDestroyView(){
		super.onDestroyView();
	}
	
	@Override
	public void onDestroy(){
		super.onDestroy();
	}
	
	@Override 
	public void onDetach(){
		super.onDetach();
	}
	
	//gets board name from dialog and allows user to define board dimensions
	private void createBoard() {
		Log.d(TAG, "switching to board creation mode.");
		BoardCreateFrag create_frag = new BoardCreateFrag();
		getActivity().getSupportFragmentManager().beginTransaction()
				.addToBackStack(null)
        		.replace(com.geoboard.R.id.board_content_container, create_frag)
        		.commit();
	}
}
